package com.zxx.view;

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.soufang.ui.R;
import com.zxx.adapter.TextAdapter;
import com.zxx.common.Common;

/**
 * @brief spinner控件区域视图
 */
public class ViewArea extends RelativeLayout implements ViewBaseAction{

		 
	private ListView mListView;
	private List<String> itemList;
	private OnSelectListener mOnSelectListener;
	private TextAdapter adapter;
	private String showText;
	private Context mContext;

	public String getShowText() {
		return showText;
	}

	public ViewArea(Context context) {
		super(context);
		init(context);
	}

	public ViewArea(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	public ViewArea(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	private void init(Context context) {
		mContext = context;
		final String[] items = getItemStr();
		
		 
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.view_distance, this, true);
		setBackgroundDrawable(getResources().getDrawable(R.drawable.choosearea_bg_right));
		mListView = (ListView) findViewById(R.id.listView);
		adapter = new TextAdapter(context, items, R.drawable.choose_item_right, R.drawable.choose_eara_item_selector);
		adapter.setTextSize(17);
		
		mListView.setAdapter(adapter);
		adapter.setOnItemClickListener(new TextAdapter.OnItemClickListener() {

			@Override
			public void onItemClick(View view, int position) {

				if (mOnSelectListener != null) {
					showText = items[position];
					mOnSelectListener.getValue(position, items[position]);
				}
			}
		});
	}

	public void setOnSelectListener(OnSelectListener onSelectListener) {
		mOnSelectListener = onSelectListener;
	}

	public interface OnSelectListener {
		
		public void getValue(int position, String showText);
	}

	@Override
	public void hide() {
		
	}

	@Override
	public void show() {
		
	}

	private String[] getItemStr()
	{
		Resources r = getResources();
		showText = r.getString(R.string.area);
		itemList = new ArrayList();
		for(int i=0;i<Common.GetLengOFDepartMen();++i)
		{
			itemList.add(i,r.getString(Common.GetDepartMenid(i)));
		}
		String[] array = (String[])itemList.toArray(new String[0]); 
		return array;
	}
	
	
}
